package com.hnchances.controller;

import com.hnchances.pojo.PageResult;
import com.hnchances.pojo.dto.GradesDTO;
import com.hnchances.pojo.dto.GradesPageDTO;
import com.hnchances.pojo.entity.Grades;
import com.hnchances.pojo.entity.Result;
import com.hnchances.service.GradesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/grades")
public class GradesController {

    private final GradesService gradesService;

    public GradesController(GradesService gradesService) {
        this.gradesService = gradesService;
    }

    @RequestMapping("/add")
    public Result<Grades> add(@RequestBody GradesDTO gradesDTO) {
        gradesService.add(gradesDTO);
        return Result.success();
    }

    @DeleteMapping("/del")
    public Result<Grades> del(Integer id) {
        gradesService.del(id);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult> page(@RequestBody GradesPageDTO gradesPageDTO) {
        PageResult pageResult = gradesService.page(gradesPageDTO);
        return Result.success(pageResult);
    }
}
